package gamestate;

import java.awt.Graphics2D;
import java.util.Stack;

/**
 * @author Ryan Hill
 */
public class StateStack 
{
	/**
	 * The stack of states
	 */
	private Stack<State> stack;
	
	/**
	 * Constructor
	 */
	public StateStack()
	{
		stack = new Stack<State>();
	}
	
	/**
	 * Update the state on the top of the stack
	 * 
	 * @param duration the time between frames
	 */
	public void update(double duration)
	{
		stack.peek().update(duration);
	}
	
	/**
	 * Render the state on the top of the stack
	 * 
	 * @param g the graphics to draw to
	 */
	public void render(Graphics2D g)
	{
		stack.peek().render(g);
	}
	
	/**
	 * Adds a state to the top of the stack
	 * 
	 * @param s the new state to add
	 */
	public void push(State s)
	{
		stack.push(s);
	}
	
	/**
	 * Takes the top state off the stack
	 */
	public void pop()
	{
		stack.pop();
	}
	
	/**
	 * @return the state on the top of the stack;
	 */
	public State getTop()
	{
		return stack.peek();
	}
	
	public State get(int i)
	{
		return stack.get(stack.size() - 1 - i);
	}
}
